--
-- PostgreSQL database dump
--

-- Dumped from database version 9.0.4
-- Dumped by pg_dump version 9.0.4
-- Started on 2012-04-26 20:25:42

SET statement_timeout = 0;
SET client_encoding = 'UTF8';
SET standard_conforming_strings = off;
SET check_function_bodies = false;
SET client_min_messages = warning;
SET escape_string_warning = off;

--
-- TOC entry 1831 (class 1262 OID 16393)
-- Dependencies: 1830
-- Name: stock; Type: COMMENT; Schema: -; Owner: stock
--

COMMENT ON DATABASE stock IS 'base de datos del proyecto stock';


--
-- TOC entry 324 (class 2612 OID 11574)
-- Name: plpgsql; Type: PROCEDURAL LANGUAGE; Schema: -; Owner: postgres
--

CREATE OR REPLACE PROCEDURAL LANGUAGE plpgsql;


ALTER PROCEDURAL LANGUAGE plpgsql OWNER TO postgres;

SET search_path = public, pg_catalog;

--
-- TOC entry 18 (class 1255 OID 16478)
-- Dependencies: 5 324
-- Name: producto_udate_fc(); Type: FUNCTION; Schema: public; Owner: postgres
--

CREATE FUNCTION producto_udate_fc() RETURNS trigger
    LANGUAGE plpgsql
    AS $$DECLARE 
id_producto_au BIGINT; 
cantidad_anterior_au BIGINT; 
cantidad_posterior_au BIGINT; 
precio_anterior_au BIGINT; 
precio_posterior_au BIGINT; 
BEGIN 
    IF (TG_OP = 'UPDATE' ) THEN id_producto_au := OLD.id; 
    cantidad_anterior_au := OLD.cantidad; 
    cantidad_posterior_au := NEW.cantidad; 
    precio_anterior_au := OLD.precio; 
    precio_posterior_au := NEW.precio; 
    insert into auditoria_producto(id_producto, cantidad_anterior, cantidad_posterior, precio_anterior, precio_posterior, motivo) 
    values (id_producto_au,cantidad_anterior_au,cantidad_posterior_au,precio_anterior_au,precio_posterior_au, 'ACTUALIZACION'); 
    RETURN NULL; 
    END IF; 
 END;$$;


ALTER FUNCTION public.producto_udate_fc() OWNER TO postgres;

SET default_tablespace = '';

SET default_with_oids = false;

--
-- TOC entry 1525 (class 1259 OID 16448)
-- Dependencies: 5
-- Name: auditoria_producto; Type: TABLE; Schema: public; Owner: stock; Tablespace: 
--

CREATE TABLE auditoria_producto (
    id bigint NOT NULL,
    cantidad_anterior bigint NOT NULL,
    cantidad_posterior bigint NOT NULL,
    precio_anterior bigint NOT NULL,
    precio_posterior bigint NOT NULL,
    motivo character varying NOT NULL,
    id_producto bigint NOT NULL
);


ALTER TABLE public.auditoria_producto OWNER TO stock;

--
-- TOC entry 1834 (class 0 OID 0)
-- Dependencies: 1525
-- Name: TABLE auditoria_producto; Type: COMMENT; Schema: public; Owner: stock
--

COMMENT ON TABLE auditoria_producto IS 'contiene todas las auditorias de la tabla productos';


--
-- TOC entry 1524 (class 1259 OID 16446)
-- Dependencies: 1525 5
-- Name: auditoria_producto_id_seq; Type: SEQUENCE; Schema: public; Owner: stock
--

CREATE SEQUENCE auditoria_producto_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.auditoria_producto_id_seq OWNER TO stock;

--
-- TOC entry 1835 (class 0 OID 0)
-- Dependencies: 1524
-- Name: auditoria_producto_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: stock
--

ALTER SEQUENCE auditoria_producto_id_seq OWNED BY auditoria_producto.id;


--
-- TOC entry 1836 (class 0 OID 0)
-- Dependencies: 1524
-- Name: auditoria_producto_id_seq; Type: SEQUENCE SET; Schema: public; Owner: stock
--

SELECT pg_catalog.setval('auditoria_producto_id_seq', 1, false);


--
-- TOC entry 1521 (class 1259 OID 16413)
-- Dependencies: 5
-- Name: producto; Type: TABLE; Schema: public; Owner: stock; Tablespace: 
--

CREATE TABLE producto (
    id bigint NOT NULL,
    codigo character varying NOT NULL,
    nombre character varying NOT NULL,
    id_tipo_producto bigint NOT NULL,
    id_proveedor bigint NOT NULL,
    cantidad bigint NOT NULL,
    precio bigint NOT NULL
);


ALTER TABLE public.producto OWNER TO stock;

--
-- TOC entry 1837 (class 0 OID 0)
-- Dependencies: 1521
-- Name: TABLE producto; Type: COMMENT; Schema: public; Owner: stock
--

COMMENT ON TABLE producto IS 'esta tabla contiene todos los productos';


--
-- TOC entry 1520 (class 1259 OID 16411)
-- Dependencies: 1521 5
-- Name: producto_id_proveedor_seq; Type: SEQUENCE; Schema: public; Owner: stock
--

CREATE SEQUENCE producto_id_proveedor_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.producto_id_proveedor_seq OWNER TO stock;

--
-- TOC entry 1838 (class 0 OID 0)
-- Dependencies: 1520
-- Name: producto_id_proveedor_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: stock
--

ALTER SEQUENCE producto_id_proveedor_seq OWNED BY producto.id_proveedor;


--
-- TOC entry 1839 (class 0 OID 0)
-- Dependencies: 1520
-- Name: producto_id_proveedor_seq; Type: SEQUENCE SET; Schema: public; Owner: stock
--

SELECT pg_catalog.setval('producto_id_proveedor_seq', 1, false);


--
-- TOC entry 1518 (class 1259 OID 16407)
-- Dependencies: 5 1521
-- Name: producto_id_seq; Type: SEQUENCE; Schema: public; Owner: stock
--

CREATE SEQUENCE producto_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.producto_id_seq OWNER TO stock;

--
-- TOC entry 1840 (class 0 OID 0)
-- Dependencies: 1518
-- Name: producto_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: stock
--

ALTER SEQUENCE producto_id_seq OWNED BY producto.id;


--
-- TOC entry 1841 (class 0 OID 0)
-- Dependencies: 1518
-- Name: producto_id_seq; Type: SEQUENCE SET; Schema: public; Owner: stock
--

SELECT pg_catalog.setval('producto_id_seq', 5, true);


--
-- TOC entry 1519 (class 1259 OID 16409)
-- Dependencies: 5 1521
-- Name: producto_id_tipo_producto_seq; Type: SEQUENCE; Schema: public; Owner: stock
--

CREATE SEQUENCE producto_id_tipo_producto_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.producto_id_tipo_producto_seq OWNER TO stock;

--
-- TOC entry 1842 (class 0 OID 0)
-- Dependencies: 1519
-- Name: producto_id_tipo_producto_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: stock
--

ALTER SEQUENCE producto_id_tipo_producto_seq OWNED BY producto.id_tipo_producto;


--
-- TOC entry 1843 (class 0 OID 0)
-- Dependencies: 1519
-- Name: producto_id_tipo_producto_seq; Type: SEQUENCE SET; Schema: public; Owner: stock
--

SELECT pg_catalog.setval('producto_id_tipo_producto_seq', 1, false);


--
-- TOC entry 1523 (class 1259 OID 16435)
-- Dependencies: 5
-- Name: proveedor; Type: TABLE; Schema: public; Owner: stock; Tablespace: 
--

CREATE TABLE proveedor (
    id bigint NOT NULL,
    nombre character varying NOT NULL,
    nombre_responsable character varying NOT NULL,
    email_responsable character varying NOT NULL,
    telefono_responsable character varying NOT NULL
);


ALTER TABLE public.proveedor OWNER TO stock;

--
-- TOC entry 1844 (class 0 OID 0)
-- Dependencies: 1523
-- Name: TABLE proveedor; Type: COMMENT; Schema: public; Owner: stock
--

COMMENT ON TABLE proveedor IS 'esta tabla es de los proveedores';


--
-- TOC entry 1522 (class 1259 OID 16433)
-- Dependencies: 5 1523
-- Name: proveedor_id_seq; Type: SEQUENCE; Schema: public; Owner: stock
--

CREATE SEQUENCE proveedor_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.proveedor_id_seq OWNER TO stock;

--
-- TOC entry 1845 (class 0 OID 0)
-- Dependencies: 1522
-- Name: proveedor_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: stock
--

ALTER SEQUENCE proveedor_id_seq OWNED BY proveedor.id;


--
-- TOC entry 1846 (class 0 OID 0)
-- Dependencies: 1522
-- Name: proveedor_id_seq; Type: SEQUENCE SET; Schema: public; Owner: stock
--

SELECT pg_catalog.setval('proveedor_id_seq', 1, true);


--
-- TOC entry 1517 (class 1259 OID 16396)
-- Dependencies: 5
-- Name: tipo_producto; Type: TABLE; Schema: public; Owner: stock; Tablespace: 
--

CREATE TABLE tipo_producto (
    id bigint NOT NULL,
    nombre character varying NOT NULL,
    descripcion character varying NOT NULL
);


ALTER TABLE public.tipo_producto OWNER TO stock;

--
-- TOC entry 1847 (class 0 OID 0)
-- Dependencies: 1517
-- Name: TABLE tipo_producto; Type: COMMENT; Schema: public; Owner: stock
--

COMMENT ON TABLE tipo_producto IS 'esta tabla contiene todos los tipos de productos';


--
-- TOC entry 1516 (class 1259 OID 16394)
-- Dependencies: 1517 5
-- Name: tipo_producto_id_seq; Type: SEQUENCE; Schema: public; Owner: stock
--

CREATE SEQUENCE tipo_producto_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.tipo_producto_id_seq OWNER TO stock;

--
-- TOC entry 1848 (class 0 OID 0)
-- Dependencies: 1516
-- Name: tipo_producto_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: stock
--

ALTER SEQUENCE tipo_producto_id_seq OWNED BY tipo_producto.id;


--
-- TOC entry 1849 (class 0 OID 0)
-- Dependencies: 1516
-- Name: tipo_producto_id_seq; Type: SEQUENCE SET; Schema: public; Owner: stock
--

SELECT pg_catalog.setval('tipo_producto_id_seq', 2, true);


--
-- TOC entry 1806 (class 2604 OID 16451)
-- Dependencies: 1524 1525 1525
-- Name: id; Type: DEFAULT; Schema: public; Owner: stock
--

ALTER TABLE auditoria_producto ALTER COLUMN id SET DEFAULT nextval('auditoria_producto_id_seq'::regclass);


--
-- TOC entry 1804 (class 2604 OID 16416)
-- Dependencies: 1521 1518 1521
-- Name: id; Type: DEFAULT; Schema: public; Owner: stock
--

ALTER TABLE producto ALTER COLUMN id SET DEFAULT nextval('producto_id_seq'::regclass);


--
-- TOC entry 1805 (class 2604 OID 16438)
-- Dependencies: 1523 1522 1523
-- Name: id; Type: DEFAULT; Schema: public; Owner: stock
--

ALTER TABLE proveedor ALTER COLUMN id SET DEFAULT nextval('proveedor_id_seq'::regclass);


--
-- TOC entry 1803 (class 2604 OID 16399)
-- Dependencies: 1516 1517 1517
-- Name: id; Type: DEFAULT; Schema: public; Owner: stock
--

ALTER TABLE tipo_producto ALTER COLUMN id SET DEFAULT nextval('tipo_producto_id_seq'::regclass);


--
-- TOC entry 1827 (class 0 OID 16448)
-- Dependencies: 1525
-- Data for Name: auditoria_producto; Type: TABLE DATA; Schema: public; Owner: stock
--

COPY auditoria_producto (id, cantidad_anterior, cantidad_posterior, precio_anterior, precio_posterior, motivo, id_producto) FROM stdin;
\.


--
-- TOC entry 1825 (class 0 OID 16413)
-- Dependencies: 1521
-- Data for Name: producto; Type: TABLE DATA; Schema: public; Owner: stock
--

COPY producto (id, codigo, nombre, id_tipo_producto, id_proveedor, cantidad, precio) FROM stdin;
3	1326456	YOUGURT 300ML	1	1	7500	100
\.


--
-- TOC entry 1826 (class 0 OID 16435)
-- Dependencies: 1523
-- Data for Name: proveedor; Type: TABLE DATA; Schema: public; Owner: stock
--

COPY proveedor (id, nombre, nombre_responsable, email_responsable, telefono_responsable) FROM stdin;
1	TREBOL	JUAN PEREZ	JUANPEREZ@TREBOL.COM.PY	(0981)123132
\.


--
-- TOC entry 1824 (class 0 OID 16396)
-- Dependencies: 1517
-- Data for Name: tipo_producto; Type: TABLE DATA; Schema: public; Owner: stock
--

COPY tipo_producto (id, nombre, descripcion) FROM stdin;
1	lacteos	producto lacteos
\.


--
-- TOC entry 1820 (class 2606 OID 16472)
-- Dependencies: 1525 1525
-- Name: pk_auditoria_producto; Type: CONSTRAINT; Schema: public; Owner: stock; Tablespace: 
--

ALTER TABLE ONLY auditoria_producto
    ADD CONSTRAINT pk_auditoria_producto PRIMARY KEY (id);


--
-- TOC entry 1812 (class 2606 OID 16456)
-- Dependencies: 1521 1521
-- Name: pk_producto; Type: CONSTRAINT; Schema: public; Owner: stock; Tablespace: 
--

ALTER TABLE ONLY producto
    ADD CONSTRAINT pk_producto PRIMARY KEY (id);


--
-- TOC entry 1816 (class 2606 OID 16443)
-- Dependencies: 1523 1523
-- Name: pk_proveedor; Type: CONSTRAINT; Schema: public; Owner: stock; Tablespace: 
--

ALTER TABLE ONLY proveedor
    ADD CONSTRAINT pk_proveedor PRIMARY KEY (id);


--
-- TOC entry 1808 (class 2606 OID 16404)
-- Dependencies: 1517 1517
-- Name: pk_tipo_producto; Type: CONSTRAINT; Schema: public; Owner: stock; Tablespace: 
--

ALTER TABLE ONLY tipo_producto
    ADD CONSTRAINT pk_tipo_producto PRIMARY KEY (id);


--
-- TOC entry 1814 (class 2606 OID 16458)
-- Dependencies: 1521 1521
-- Name: uk_codigo; Type: CONSTRAINT; Schema: public; Owner: stock; Tablespace: 
--

ALTER TABLE ONLY producto
    ADD CONSTRAINT uk_codigo UNIQUE (codigo);


--
-- TOC entry 1810 (class 2606 OID 16406)
-- Dependencies: 1517 1517
-- Name: uk_nombre; Type: CONSTRAINT; Schema: public; Owner: stock; Tablespace: 
--

ALTER TABLE ONLY tipo_producto
    ADD CONSTRAINT uk_nombre UNIQUE (nombre);


--
-- TOC entry 1818 (class 2606 OID 16445)
-- Dependencies: 1523 1523
-- Name: uk_proveedor_nombre; Type: CONSTRAINT; Schema: public; Owner: stock; Tablespace: 
--

ALTER TABLE ONLY proveedor
    ADD CONSTRAINT uk_proveedor_nombre UNIQUE (nombre);


--
-- TOC entry 1823 (class 2606 OID 16473)
-- Dependencies: 1525 1521 1811
-- Name: fk_auditoria_producto; Type: FK CONSTRAINT; Schema: public; Owner: stock
--

ALTER TABLE ONLY auditoria_producto
    ADD CONSTRAINT fk_auditoria_producto FOREIGN KEY (id_producto) REFERENCES producto(id) DEFERRABLE;


--
-- TOC entry 1821 (class 2606 OID 16459)
-- Dependencies: 1523 1815 1521
-- Name: fk_producto_proveedor; Type: FK CONSTRAINT; Schema: public; Owner: stock
--

ALTER TABLE ONLY producto
    ADD CONSTRAINT fk_producto_proveedor FOREIGN KEY (id_proveedor) REFERENCES proveedor(id);


--
-- TOC entry 1822 (class 2606 OID 16464)
-- Dependencies: 1517 1521 1807
-- Name: fk_producto_tipo_producto; Type: FK CONSTRAINT; Schema: public; Owner: stock
--

ALTER TABLE ONLY producto
    ADD CONSTRAINT fk_producto_tipo_producto FOREIGN KEY (id_tipo_producto) REFERENCES tipo_producto(id);


--
-- TOC entry 1833 (class 0 OID 0)
-- Dependencies: 5
-- Name: public; Type: ACL; Schema: -; Owner: postgres
--

REVOKE ALL ON SCHEMA public FROM PUBLIC;
REVOKE ALL ON SCHEMA public FROM postgres;
GRANT ALL ON SCHEMA public TO postgres;
GRANT ALL ON SCHEMA public TO PUBLIC;


-- Completed on 2012-04-26 20:25:43

--
-- PostgreSQL database dump complete
--

